home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / varia / egebook.lha / ege.book / 1 / Course1.C next >
C/C++ Source or Header  |  1992-06-04  |  1KB  |  59 lines

  1. #include <stdio.h>
  2.  
  3. class Teacher {
  4.   char *name;               // name of teacher
  5. public:
  6.   void setName(char *newName){   // member function
  7.     name = newName;
  8.   };
  9.   void print(){
  10.     printf("the teachers name is: %s \n", name);
  11.   };
  12. };
  13.  
  14. class Student{
  15.   char *name;       // name of student
  16. };
  17.  
  18. class Course {
  19.   char *number;          
  20.   char *time;
  21.   Student students[25];
  22. public:
  23.   Teacher *teacher;
  24.   Course(){                  // NEW:
  25.     number = "unassigned";   // constructor with no parameters
  26.     time = "TBA";
  27.   };
  28.   Course(char *n, char *t){  // constructor with parameters
  29.     number = n;
  30.     time = t;
  31.   };
  32.   void print(){
  33.     printf("Course number: %s, at: %s \n", number, time);
  34.   };
  35. };
  36.  
  37. main() {
  38.   Course c1;                 // constructor is called 
  39.                              // with no parameters
  40.   Course c2("COP 4225","MW 1030-1200");
  41.                              // constructor is called
  42.                              // with two explicit parameters
  43.   c1.print();
  44.   c2.print();
  45.  
  46.   Course *c3;                // C++ allows to mix
  47.   Course *c4;                //  declarations and statements
  48.  
  49.   c3 = new Course;           // constructor is called
  50.                              // with no parameters
  51.   c4 = new Course("COP 6611","TR 1030-1200");
  52.                              // constructor is called
  53.                              // with two explicit parameters
  54.   c3->print();
  55.   c4->print();
  56. }
  57.  
  58.  
  59.